﻿CREATE TABLE [dbo].[UserAccount] (
    [Id]           UNIQUEIDENTIFIER CONSTRAINT [DF_UserAccount_Id] DEFAULT (newid()) NOT NULL,
    [Username]     NVARCHAR (50)    NOT NULL,
    [PasswordHash] NVARCHAR (MAX)   NOT NULL,
    [PasswordSalt] NVARCHAR (50)    CONSTRAINT [DF_UserAccount_PasswordSalt] DEFAULT (CONVERT([nvarchar],rand())) NOT NULL,
    [DateActive]   DATE             CONSTRAINT [DF_UserAccount_DateActive] DEFAULT (getdate()) NOT NULL,
    [DateInactive] DATE             NULL,
    [Status]       TINYINT          CONSTRAINT [DF_UserAccount_Status] DEFAULT ((0)) NOT NULL,
    [CompanyId]    UNIQUEIDENTIFIER NOT NULL,
    CONSTRAINT [PK_UserAccount] PRIMARY KEY CLUSTERED ([Id] ASC),
    CONSTRAINT [FK_UserAccount_Company] FOREIGN KEY ([CompanyId]) REFERENCES [dbo].[Company] ([Id])
);




GO
CREATE UNIQUE NONCLUSTERED INDEX [IX_UserAccount]
    ON [dbo].[UserAccount]([Username] ASC);

